package com.hkts.management.unattended.poundroom.service.serviceimpl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.unattended.poundroom.entity.YbMutualCompany;
import com.hkts.management.unattended.poundroom.entity.YbMutualInventory;
import com.hkts.management.unattended.poundroom.entity.YbMutualInventoryclass;
import com.hkts.management.unattended.poundroom.mapper.YbMutualInventoryMapper;
import com.hkts.management.unattended.poundroom.service.IYbMutualInventoryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zy
 * @since 2021-10-13
 */
@Service
@Transactional
@DS("slave")
public class YbMutualInventorySlaveServiceImpl extends ServiceImpl<YbMutualInventoryMapper, YbMutualInventory> {


    @Autowired
    private YbMutualInventoryMapper ybMutualInventoryMapper;

    public IPage<YbMutualInventory> selectPage(Page<YbMutualInventory> page, YbMutualInventory ybMutualInventory) {
        QueryWrapper<YbMutualInventory> query = Wrappers.query();
        return ybMutualInventoryMapper.selectPage(page, query);
    }


    public List<YbMutualInventory> selectList(YbMutualInventory ybMutualInventory) {
        QueryWrapper<YbMutualInventory> query = Wrappers.query();
        return ybMutualInventoryMapper.selectList(query);
    }

    public List<YbMutualInventory> getUpdateTimeData(LocalDateTime updateTime,int flag){
        QueryWrapper<YbMutualInventory> query = Wrappers.query();
        query.select("top 1000  cInvCode, cInvName, cInvStd,cInvCCode, cComUnitName, cAssComUnitName,InvHS, bPurchase, bSale, cDefWareHouse, bInvBatch, bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus");
        query.lambda().gt(updateTime!=null,YbMutualInventory::getDoptTime,updateTime);
        query.orderByAsc("cInvCode");
        if(flag!=0){
            Integer count=flag*1000;
            String maxId=ybMutualInventoryMapper.getAutoIdMax(count);
            query.ge("cInvCode",maxId);
        }
        return ybMutualInventoryMapper.selectList(query);
    }
    public Integer getUpdateTimeCount(LocalDateTime updateTime){
        QueryWrapper<YbMutualInventory> query = Wrappers.query();
        query.lambda().gt(updateTime!=null,YbMutualInventory::getDoptTime,updateTime);
        Integer count=ybMutualInventoryMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public Integer getBmutualStatusCount(){
        QueryWrapper<YbMutualInventory> query = Wrappers.query();
        query.lambda().eq(YbMutualInventory::getBmutualStatus,0);
        Integer count=ybMutualInventoryMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public List<YbMutualInventory> getBmutualStatuData(int flag){
        QueryWrapper<YbMutualInventory> query = Wrappers.query();
        query.select("top 1000  cInvCode, cInvName, cInvStd,cInvCCode, cComUnitName, cAssComUnitName,InvHS, bPurchase, bSale, cDefWareHouse, bInvBatch, bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus");
        query.lambda().eq(YbMutualInventory::getBmutualStatus,0);
        query.orderByAsc("cInvCode");
        if(flag!=0){
            Integer count=flag*1000;
            String maxId=ybMutualInventoryMapper.getAutoIdMax(count);
            query.ge("cInvCode",maxId);
        }
        return ybMutualInventoryMapper.selectList(query);
    }
}
